package com.me.jingdongshop.ui.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.me.common.base.Global;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.HomeQuick;
import com.me.jingdongshop.model.protocol.IHttpService;
import com.me.jingdongshop.ui.activity.ProductlistActivity;
import com.me.jingdongshop.ui.view.CircleImageView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuer on 2017/5/8/008.
 * 促销快报类的适配器
 */

public class HomePromotionLetterAdapter extends RecyclerView.Adapter<HomePromotionLetterAdapter.ViewHolder>{
    private RecyclerView recyclerView;

    public List<HomeQuick.TopicBean> mTopicBeen=new ArrayList<>();

    public HomePromotionLetterAdapter(List<HomeQuick.TopicBean> topicBeen) {
        super();
        this.mTopicBeen = topicBeen;
    }

    @Override
    public HomePromotionLetterAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_rv_promotion_letter_item, viewGroup, false);
        HomePromotionLetterAdapter.ViewHolder vh=new HomePromotionLetterAdapter.ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(HomePromotionLetterAdapter.ViewHolder holder, int position) {
        RecyclerView.ViewHolder viewHolder = holder;
        String pic = mTopicBeen.get(position).getPic();
        Picasso.with(Global.mContext).load(IHttpService.HOST_URL+pic).into(holder.homePromotionLetterCircleImg);
        String name = mTopicBeen.get(position).getName();
        holder.tvName.setText(name);

        //跳转到商品列表
        holder.llHomePro.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(v.getContext(), ProductlistActivity.class);
                v.getContext().startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return mTopicBeen==null?0:mTopicBeen.size();
    }
    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public class ViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout llHomePro;
        //圆形图片
        private CircleImageView homePromotionLetterCircleImg;
        private TextView tvName;

        public ViewHolder(View view) {
            super(view);

            llHomePro = (LinearLayout) view.findViewById(R.id.ll_home_pro);
            homePromotionLetterCircleImg = (CircleImageView) view.findViewById(R.id.home_promotion_letter_circle_img);
            tvName = (TextView) view.findViewById(R.id.tv_name);

        }
    }
}
